var OptPool = require('./module/OptPool');
var optpool = new OptPool();
var pool = optpool.getPool();

// 从连接池中获取一个连接
pool.getConnection(function(err, conn){
	
	// --插入数据
    var userAddSql = 'insert into user (uname,pwd) values(?,?)'; 
    var param = ['aaa','1111'];
    conn.query(userAddSql, param, function(err, rs){
        if(err){ 
            console.log('insert err:', err.message); 
            return; 
        } 
        console.log('insert success'); 
        // conn.release(); // 放回连接池 (只在最后一步操作)
    });
	
	 conn.query('SELECT * from user', function(err, rs) { 
        if (err) { 
            console.log('[query] - :'+err); 
            return; 
        }   
        for(var i=0;i<rs.length;i++){
            console.log(rs[i].uname); 
        }
        conn.release(); //放回连接池
    });
});